<template>
	<view class="item-box" :style="{width:width || '100%'}">
		<view :style="{background:bgColor,height:height}" @click="choose(item)"
			:class="['item',current === item.id?'active':'']" v-for="item in list" :key="item.id">
			<image :src="item.image_active" v-show="item.image && current === item.id" class="image"></image>
			<image :src="item.image" v-show="item.image && current != item.id" class="image"></image>
			<text>{{item.name}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		/*list结构
		{
			id:1,
			name:'男',
			image:'',// 未选中图标
			image_active:'',// 选中图标
		}
		*/
		props: ['list', 'value', 'width', 'bgColor', 'height'],
		name: "radioButton",
		data() {
			return {
				current: this.value,
			}
		},
		methods: {
			choose(item) {
				this.current = item.id;
				this.$emit('input', item.id);
			}
		},
		watch: {
			value(val) {
				this.current = val;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.item-box {
		display: flex;
		width: 100%;

		.item {
			background-color: #F6F7FB;
			height: 34px;
			text-align: center;
			color: #808080;
			font-size: 14px;
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;

			.image {
				width: 16px;
				height: 16px;
				margin-right: 6px;
			}

			&:first-child {
				border-radius: 4px 0 0 4px;
			}

			&:last-child {
				border-radius: 0 4px 4px 0;
			}

			&.active {
				border-radius: 4px;
				background: #FFCF0B !important;
				color: #333;
			}
		}
	}
</style>
